import httpClient from "@/utils/request";
import type {
  CreatePermissionParams,
  PageResult,
  PermissionListParams,
  PermissionTree,
  PermissionVO,
  UpdatePermissionParams,
  UpdatePermissionStatusParams
} from "./types";

/**
 * 更新权限
 * @param data 权限信息
 */
export function updatePermission(data: UpdatePermissionParams) {
  return httpClient.post<PermissionVO>("/system/permission/update", data);
}

/**
 * 更新权限状态
 * @param data 状态信息
 */
export function updatePermissionStatus(data: UpdatePermissionStatusParams) {
  return httpClient.post<string>("/system/permission/status/update", data);
}

/**
 * 获取权限列表
 * @param params 查询参数
 */
export function getPermissionList(params?: PermissionListParams) {
  return httpClient.get<PageResult<PermissionVO>>(
    "/system/permission/list",
    params
  );
}

/**
 * 获取权限树
 */
export function getPermissionTree() {
  return httpClient.get<PermissionTree>("/system/permission/tree");
}

/**
 * 获取权限信息
 * @param permissionId 权限ID
 */
export function getPermissionInfo(permissionId: string) {
  return httpClient.get<PermissionVO>("/system/permission/info", {
    permissionId
  });
}

/**
 * 获取权限模块列表
 */
export function getPermissionModuleList() {
  return httpClient.get<Record<number, string>>("/system/permission/module");
}

/**
 * 创建权限
 * @param data 权限信息
 */
export function createPermission(data: CreatePermissionParams) {
  return httpClient.post<PermissionVO>("/system/permission/create", data);
}

/**
 * 删除权限
 * @param permissionId 权限ID
 */
export function deletePermission(permissionId: string) {
  return httpClient.delete<string>("/system/permission/delete", {
    params: { permissionId }
  });
}
